package fragment.livefragments;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.lanou.horo.myapplication.R;

import java.util.List;

import entity.LiveMoreEntity;
import entity.LivePageEntity;
import fragment.AbsBaseFragment;
import utils.adapter.LiveMoreAdpter;
import volley.VolleySingleton;

/**
 * 直播更多页面
 * Created by dllo on 15/11/24.
 */
public class LiveMoreFragment extends AbsBaseFragment {
    private RecyclerView recyclerView;
    private LiveMoreAdpter adpter;
    private ImageView titleForAllBack;
    private TextView title;

    @Override
    protected int getLayoutView() {
        return R.layout.fragment_live_more;
    }

    @Override
    protected void initView() {
        titleForAllBack = findView(R.id.titleForAllBack);
        titleForAllBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goBack();
            }
        });
        title = findView(R.id.titleForAllTv);
        title.setText("电台排行榜");
        recyclerView = findView(R.id.liveMoreRecylerView);
        adpter = new LiveMoreAdpter();
        GridLayoutManager manager = new GridLayoutManager(getContext(),1);
        recyclerView.setAdapter(adpter);
        recyclerView.setLayoutManager(manager);


    }

    @Override
    protected void initData() {
        initNetwork();
    }

    String URL = "http://live.ximalaya.com/live-web/v1" +
            "/getTopRadiosList?device=android&radioNum=20";

    private void initNetwork() {
        VolleySingleton.getInstance().addRequest(URL,
                LiveMoreEntity.class, new Response.Listener<LiveMoreEntity>() {
                    @Override
                    public void onResponse(LiveMoreEntity response) {
                        if (response != null) {
                            List<LiveMoreEntity.ResultEntity>result = response.getResult();
                            if (result!=null){
                                adpter.addData(result);

                            }


                        }

                        dismissDialog();
                    }

                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        dismissDialog();
                        toastError();
                    }
                });
        showDialog();
    }

}
